package projectFileIO;

import java.io.*;
import java.util.*;

public class FileIOFunctions {
	
	File input = new File("input.txt");
	File output = new File("output.txt");

	public FileIOFunctions() {

	}

	public void inputFile(File file, String contents) throws IOException {
		PrintWriter input = new PrintWriter(new FileWriter(file, true));
		Date date = new Date();
		if (contents.length() <= 140) {
			input.println(date + ": " + contents);
			input.close();
		} else {
			FileIOGUImain.updateDirections("That's too many characters!");
		}
	}

	public void outputFile() throws IOException {
		FileIOGUImain.eraseJTextAreaOutput();
		BufferedReader in = new BufferedReader(new FileReader(output));
		String contents;
		while ((contents = in.readLine()) != null) {
			FileIOGUImain.updateJTextAreaOutput(contents);
			FileIOGUImain.updateJTextAreaOutput("\r\n");
		}
	}

	public void copyFile() throws IOException {
		BufferedReader in = new BufferedReader(new FileReader(input));
		FileWriter out = new FileWriter(output, false);
		String contents;
		while ((contents = in.readLine()) != null) {
			out.write(contents + "\r\n");
		}
		in.close();
		out.close();
	}
}
